#Region " Imports "

Imports BlazeApps.Library.Page
Imports BA.Mail
Imports System.Configuration.ConfigurationManager
Imports System.Text

#End Region

Partial Class Usercontrols_Email
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "



#End Region

#Region " Page Events "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.MessageLabel = Me.uxMessagesLabel
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        SetPageTitle("Email")

        ConfigBaseEditorCtrls()

		BuildFCKEditor(EditorPageType.SingleEditor)

        If IsUserAuthenticated = True Then
            If Me.Page.IsPostBack = False Then
                If GetStringFromQueryString("userid") <> String.Empty Then
                    Me.uxEmailToTextBox.Text = Membership.GetUser(GetStringFromQueryString("userid")).Email.ToString.Trim
                End If

                Me.uxEmailFromTextBox.Text = Membership.GetUser(CurrentUser).Email.ToString.Trim
            End If
        End If

        If GetBooleanFromQueryString("mailarticle") = True Then
            GeneratePageEmail()
        End If

        Me.uxMemberPanel.Visible = ShowControls(SecurityMask.Member, True)

    End Sub

#End Region

#Region " Save Data "



#End Region

#Region " Load Data "



#End Region

#Region " Form Controls Events "

    Protected Sub uxSubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxSubmitButton.Click
        If Page.IsValid Then
			SendEmail(Me.uxEmailToTextBox.Text.ToString.Trim, Me.uxEmailCCTextBox.Text.ToString.Trim, Me.uxEmailBCCTextBox.Text.ToString.Trim, Me.uxEmailFromTextBox.Text.ToString, Me.uxEmailSubjectTextBox.Text.ToString, Me.uxEmailTextbox.Value, True)
		End If
	End Sub

#End Region

#Region " Helpers and Methods "

	Private Sub ConfigBaseEditorCtrls()
		Me.FCKEditor = Me.uxEmailTextbox
	End Sub

	Private Sub GeneratePageEmail()
		Dim PageItems As PageDetail = PageDetail.GetPageDetail(GetGuidFromQueryString("id"))
		Dim EmailBody As New StringBuilder

		Me.uxEmailSubjectTextBox.Text = String.Format("{0} {1}", Resources.Resource.EmailingItem, PageItems.title)

		EmailBody.Append(Resources.Resource.DoNotEdit)
		EmailBody.Append("<br>")
		EmailBody.Append(Resources.Resource.AutoGeneratedEmail)
		EmailBody.Append("<br>")
		EmailBody.Append("<a href=""http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL") & "?pid=viewer&id=" & GetStringFromQueryString("id") & """>" & PageItems.title & "</a>")
		EmailBody.Append("<br>")
		EmailBody.Append(Resources.Resource.EditsCanBegin)
		Me.uxEmailTextbox.Value = EmailBody.ToString
	End Sub

#End Region

End Class
